#pragma region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU Lesser General Public License.
/// </copyright>
#pragma endregion

#pragma once

//*********************************************************
// OSHProtocol
//*********************************************************
class ATL_NO_VTABLE OSHProtocol :
	public CComObjectRootEx<CComGlobalsThreadModel>,
	public CComCoClass<OSHProtocol>,
	public OSHLibrary::IProtocol,
	public IClassFactory
{
private:
	bool _initialized;
	bool _httpProtocolEnabled;
	bool _fileProtocolEnabled;
	CComBSTR _basePath;
	CComPtr<OSHLibrary::IProtocolSink> _protocolSink;
	CComPtr<IClassFactory> _fileHelperClassFactory;
	CComPtr<IClassFactory> _httpHelperClassFactory;

	HRESULT CreateHelperClassFactory(REFCLSID helperClassID, CComPtr<IClassFactory>& classFactory);
	HRESULT ReleaseHelperClassFactory(CComPtr<IClassFactory>& classFactory);
	HRESULT CreateHelperInstance(REFIID riid, IClassFactory* classFactory, void** ppvObject);

public:
	DECLARE_REGISTRY_RESOURCEID(IDR_OSHPROTOCOL)

	BEGIN_COM_MAP(OSHProtocol)
		COM_INTERFACE_ENTRY(OSHLibrary::IProtocol)
		COM_INTERFACE_ENTRY(IClassFactory)
	END_COM_MAP()

	OSHProtocol();
	virtual ~OSHProtocol();


	//*********************************************************
	// IClassFactory
	//*********************************************************
	STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj);
	STDMETHOD(LockServer)(BOOL /*fLock*/);


	//*********************************************************
	// IProtocol
	//*********************************************************
	STDMETHOD(Register)(VARIANT_BOOL enableHttpProtocol, VARIANT_BOOL enableFileProtocol, BSTR httpRootFolder,
		OSHLibrary::IProtocolSink* protocolSink);
	STDMETHOD(Unregister)();
};

OBJECT_ENTRY_AUTO(__uuidof(OSHLibrary::Protocol), OSHProtocol)

